package cn.edu.just.firstjavaapp.l8;

public class Test01 {
    public static void main(String[] args) {
        Person[] persons = new Person[10];

        persons[0] = new Person("Alice", 25);
        persons[1] = new Person("Bob", 30);
        persons[2] = new Person("Charlie", 22);
        persons[3] = new Person("David", 28);
        persons[4] = new Person("Eve", 24);
        persons[5] = new Person("Frank", 32);
        persons[6] = new Person("Grace", 26);
        persons[7] = new Person("Hank", 29);
        persons[8] = new Person("Ivy", 23);
        persons[9] = new Person("Jack", 31);

        Rectangle[] rectangles = new Rectangle[10];

        // 创建10个矩形对象并存储到数组中
        rectangles[0] = new Rectangle(5, 10);
        rectangles[1] = new Rectangle(8, 12);
        rectangles[2] = new Rectangle(3, 7);
        rectangles[3] = new Rectangle(10, 15);
        rectangles[4] = new Rectangle(6, 9);
        rectangles[5] = new Rectangle(4, 8);
        rectangles[6] = new Rectangle(7, 11);
        rectangles[7] = new Rectangle(9, 14);
        rectangles[8] = new Rectangle(2, 5);
        rectangles[9] = new Rectangle(11, 18);

        sort(persons);

        for(Person p:persons){
            p.print();
        }
        System.out.println("-----------");
        sort(rectangles);
        for(Rectangle r:rectangles){
            r.print();
        }
    }

    public static void sort(Relatable[] relatables){
        for(int i=0;i<relatables.length-1;i++){
            for(int j=0;j<relatables.length-i-1;j++){
                if(relatables[j].isLargerThan(relatables[j+1])>0){
                    Relatable temp = relatables[j];
                    relatables[j] = relatables[j+1];
                    relatables[j+1] = temp;
                }
            }
        }
    }
}
